﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EBAYVN.DAO;
using EBAYVN.DOMAIN;
namespace EBAYVN.CUSTOMERS.UserControl
{
    public partial class MenuBar : System.Web.UI.UserControl
    {
        private LoaiSanPhamDao _lspDao = new LoaiSanPhamDao();
        private NhaSanXuatDao _nsxDao = new NhaSanXuatDao();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadReference();
            }
        }
        private void LoadReference()
        {
            var list = _lspDao.GetList();
            repeater.DataSource = list;
            repeater.DataBind();
        }
        protected void repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (!e.Item.ItemType.Equals(ListItemType.Item) &&
                !e.Item.ItemType.Equals(ListItemType.AlternatingItem)) return;

            var item = (LOAISANPHAM)(e.Item.DataItem);
            if (item == null) return;
            var child = (Repeater)e.Item.FindControl("rpChild");
            if (child == null) return;
            // bind nhà sản xuất
            var list = _nsxDao.GetListCTNhaSanXuatByLoaiSanPham(item.MALOAISP);
            if (list.Count > 0)
            {
                child.DataSource = list;
                child.DataBind();
            }
            else
            {
                child.Visible = false;
            }
        }
    }
}